package com.etoppaas.performance.service.impl;

import java.util.List;

import com.etoppaas.performance.common.PerformanceConstants;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.etoppaas.performance.mapper.PerTemplateSpecRelationMapper;
import com.etoppaas.performance.domain.PerTemplateSpecRelation;
import com.etoppaas.performance.service.IPerTemplateSpecRelationService;
import com.ruoyi.common.core.text.Convert;

/**
 *  服务层实现
 * 
 * @author ruoyi
 * @date 2019-06-05
 */
@Service
public class PerTemplateSpecRelationServiceImpl implements IPerTemplateSpecRelationService 
{
	@Autowired
	private PerTemplateSpecRelationMapper perTemplateSpecRelationMapper;

	/**
     * 查询信息
     * 
     * @param templateId ID
     * @return 信息
     */
    @Override
	public PerTemplateSpecRelation selectPerTemplateSpecRelationById(Long templateId)
	{
	    return perTemplateSpecRelationMapper.selectPerTemplateSpecRelationById(templateId);
	}
	
	/**
     * 查询列表
     * 
     * @param perTemplateSpecRelation 信息
     * @return 集合
     */
	@Override
	public List<PerTemplateSpecRelation> selectPerTemplateSpecRelationList(PerTemplateSpecRelation perTemplateSpecRelation)
	{
	    return perTemplateSpecRelationMapper.selectPerTemplateSpecRelationList(perTemplateSpecRelation);
	}
	
    /**
     * 新增
     * 
     * @param perTemplateSpecRelation 信息
     * @return 结果
     */
	@Override
	public int insertPerTemplateSpecRelation(PerTemplateSpecRelation perTemplateSpecRelation)
	{
	    return perTemplateSpecRelationMapper.insertPerTemplateSpecRelation(perTemplateSpecRelation);
	}
	
	/**
     * 修改
     * 
     * @param perTemplateSpecRelation 信息
     * @return 结果
     */
	@Override
	public int updatePerTemplateSpecRelation(PerTemplateSpecRelation perTemplateSpecRelation)
	{
	    return perTemplateSpecRelationMapper.updatePerTemplateSpecRelation(perTemplateSpecRelation);
	}

	/**
     * 删除对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deletePerTemplateSpecRelationByIds(String ids)
	{
		return perTemplateSpecRelationMapper.deletePerTemplateSpecRelationByIds(Convert.toStrArray(ids));
	}

	@Override
	public int updateWeight(List<PerTemplateSpecRelation> relations) {
		for(PerTemplateSpecRelation relation:relations){
			perTemplateSpecRelationMapper.updatePerTemplateSpecRelation(relation);
		}
		return relations.size();
	}

	@Override
	public String checkIsLegal(PerTemplateSpecRelation relation) {
		relation.setWeight(null);
		List<PerTemplateSpecRelation> relations=perTemplateSpecRelationMapper.selectPerTemplateSpecRelationList(relation);
		if(CollectionUtils.isEmpty(relations)){
			return PerformanceConstants.TEMPLATE_SPEC_UNREPEAT;
		}else {
			return PerformanceConstants.TEMPLATE_SPEC_REPEAT;
		}
	}
}
